package cn.psvmc.cxzapi.controller.ticket;

import cn.psvmc.cxzapi.model.common.*;
import cn.psvmc.cxzapi.model.ticket.TTicket;
import cn.psvmc.cxzapi.response.*;
import cn.psvmc.cxzapi.service.ticket.TTicketService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 工单管理
 * @Author auto
 * @Date 2024-08-12
 */
@RestController
@RequestMapping("/ticket")
public class TTicketController {

    @Resource
    private TTicketService tTicketService;

    /**
    * @Author auto 2024-08-12 新增工单表
    * @Param tTicket 工单表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TTicket tTicket) {
        ToolUtils.validation(new Object[]{
                tTicket.getTypeId(), "工单类型id", 1
                , tTicket.getTcid(), "工单原因id", 1
                , tTicket.getOrderCode(), "订单编号", 2
                , tTicket.getTitle(), "工单标题", 2
        });
        int addResult = tTicketService.add(tTicket);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
    * @Author auto 2024-08-12 查询工单表详情
    * @Param [entity]
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/detail")
    public Result detail(@RequestBody DetailEntity entity) {
        Integer id = entity.getId();
        ToolUtils.validation(new Object[]{id, "id", 1});
        return ResultGenerator.genSuccessResult("查询成功", tTicketService.detail(id));
    }

    /**
    * @Author auto 2024-08-12 查询工单表列表
    * @Param entity 分页查询通用实体类
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/list")
    public PageResult2 list(@RequestBody SearchEntity entity) {
        Page<TTicket> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tTicketService.list(queryPage, entity));
    }

    /**
     * @Description 完结
     * @Date 2024/8/13 14:33
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/end")
    public Result end(@RequestBody DetailEntity entity) {
        Integer id = entity.getId();
        ToolUtils.validation(new Object[]{id, "id", 1});
        tTicketService.end(id);
        return ResultGenerator.genSuccessResult("完结成功！");
    }
}
